package com.pactera.madp.cp.controller.oms.wm;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.bo.FromUserInfoBO;
import com.pactera.madp.cp.api.dto.ReqToUsersDTO;
import com.pactera.madp.cp.api.dto.wm.ReqMsgIndexDTO;
import com.pactera.madp.cp.service.IChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

/**
 * @author: yangpengwei
 * @time: 2020/12/2 11:05 上午
 * @description 会话内容存档
 */
@RestController
@AllArgsConstructor
@RequestMapping("/workmessage")
@Api(value = "workmessage", tags = "会话内容存档")
public class ChatServiceController {

    private IChatService chatService;

    /**
     * 会话内容存档 - 会话员工下拉
     *
     * @param name   搜索名称 [可选]
     */
    @GetMapping("/fromusers")
    @ApiOperation(value = "员工/客户检索")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="搜索名称 [可选]",dataType ="String"),
            @ApiImplicitParam(name="type",value="用户类型，0-员工检索，1-客户检索",dataType ="Integer")
    })
    public R<Page<FromUserInfoBO>> fromUsers(@RequestParam(required = false,value = "name") String name, @RequestParam(value = "type") Integer type, @RequestParam(required = false,value = "deptId") Integer deptId, Page page) {
        return R.ok(chatService.getFromUserInfoList(name,type,deptId,page));
    }

    @GetMapping("/fromusers-con")
    @ApiOperation(value = "客户检索")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="搜索名称 [可选]",dataType ="String"),
    })
    public R<Page<FromUserInfoBO>> fromUsers(@RequestParam(required = false,value = "name") String name, Page page) {
        return R.ok(chatService.getFromUserInfoListByContact(name,page));
    }

    @GetMapping("/fromusers-emp")
    @ApiOperation(value = "员工检索")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="搜索名称 [可选]",dataType ="String"),
            @ApiImplicitParam(name="deptId",value="部门id",dataType ="Integer")
    })
    public R<List<FromUserInfoBO>> fromUsersByEmp(@RequestParam(required = false,value = "name") String name,@RequestParam(required = false,value = "deptId") Integer deptId) {
        return R.ok(chatService.getFromUserInfoList(name,deptId));
    }

    /**
     * 会话内容存档 - 会话对象列表
     */
    @GetMapping("/to-users")
    @ApiOperation(value = "会话对象列表(成员)")
    public R toUsers(@Validated ReqToUsersDTO req, Page page) {
        return chatService.getToUserInfoList(req,page);
    }

    /**
     * 会话内容存档 - 会话对象列表
     */
    @GetMapping("/to-contact")
    @ApiOperation(value = "会话对象列表(客户)")
    public R toContact(ReqToUsersDTO req, Page page) {
        return chatService.getToContactInfoList(req,page);
    }

    /**
     * 会话内容存档 - 列表
     */
    @GetMapping("/page")
    @ApiOperation(value = "会话内容存档 - 聊天记录查看")
    public R chatList(ReqMsgIndexDTO req,Page page) {
        return chatService.index(req,page);
    }

    /**
     * 会话内容存档 - 列表
     */
    @GetMapping("/index")
    @ApiOperation(value = "会话内容存档 - 全局搜索")
    public R allChatList(ReqMsgIndexDTO req,Page page) {
        return chatService.indexPage(req,page);
    }

    @SysLog("会话内容存档-导出Excel")
    @PostMapping("/excel")
    @ApiOperation(value = "导出Excel")
    public void exitExcelList(@RequestBody ReqMsgIndexDTO req, HttpServletResponse response, OutputStream out) throws IOException {
        chatService.exitExcelList(req,response,out);
    }

}
